home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / IDENTDIC.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  2KB  |  67 lines

  1. /* IdentDict.c -- implementation of Identifier Dictionary
  2.  
  3. Function:
  4.     
  5. An IdentDict is like a Dictionary, except keys are compared using
  6. isSame() rather than isEqual().
  7.  
  8. */
  9.  
  10. #include "identdic.h"
  11. #include "lookupke.h"
  12.  
  13. #define THIS    IdentDict
  14. #define BASE    Dictionary
  15. DEFINE_CLASS(IdentDict,Dictionary);
  16.  
  17. IdentDict::IdentDict(unsigned size) : Dictionary(size) {}
  18.  
  19. IdentDict::IdentDict(const IdentDict& d) : Dictionary(d) {}
  20.  
  21. void IdentDict::operator=(const IdentDict& d)
  22. {
  23.     this->Dictionary::operator=(d);
  24. }
  25.  
  26. int IdentDict::findIndexOf(const Object& ob) const
  27. /*
  28. Search this IdentDict for a LookupKey with the same key object as the
  29. argument.
  30.  
  31. Enter:
  32.     ob = pointer to LookupKey to search for
  33.  
  34. Returns:
  35.     index of object if found or of nil slot if not found
  36.     
  37. Algorithm L, Knuth Vol. 3, p. 519
  38. */
  39. {
  40.     register int i;
  41.     Object* keyob = ((LookupKey*)&ob)->key();
  42.     for (i = h((int)keyob); contents[i]!=nil; i = (i-1)&mask) {
  43.         if (((LookupKey*)contents[i])->key()->isSame(*keyob)) return i;
  44.     }
  45.     return i;
  46. }
  47.  
  48. Object* IdentDict::atKey(const Object& key) const
  49. {
  50.     return Dictionary::atKey(LookupKey(key));
  51. }
  52.  
  53. Object* IdentDict::atKey(const Object& key, const Object& newValue)
  54. {
  55.     return Dictionary::atKey(LookupKey(key), newValue);
  56. }
  57.  
  58. LookupKey& IdentDict::assocAt(const Object& key) const
  59. {
  60.     return Dictionary::assocAt(LookupKey(key));
  61. }
  62.  
  63. bool IdentDict::includesKey(const Object& key) const
  64. {
  65.     return Dictionary::includesKey(LookupKey(key));
  66. }
  67.